import * as types from '../constants/actionTypes';
import initialState from '../../reducers/initialState';
import _ from 'lodash';

export default function(state=initialState.order, action)
{
    let order = null;
    switch(action.type){
        case types.ORDER_DETAIL:
            order = Object.assign({},state,{order_detail: action.order_detail});
            return order;
        case types.SEND_ADDRESS:
            order = Object.assign({},state,{send_address: action.send_address, send_location: action.send_location});
            return order;
        case types.RECEIVE_ADDRESS:
            order = Object.assign({},state,{receive_address: action.receive_address, receive_location: action.receive_location});
            return order;
        case types.BUY_SEND_ADDRESS:
            order = Object.assign({},state,{buy_send_address: action.buy_send_address, buy_send_location: action.buy_send_location});
            return order;
        case types.BUY_RECEIVE_ADDRESS:
            order = Object.assign({},state,{buy_receive_address: action.buy_receive_address, buy_receive_location: action.buy_receive_location});
            return order;
        case types.DONE_OBJ_PRICE:
            order = {...state};
            if(action.done_obj_price){
                if(action.done_obj_price instanceof Array){
                    order.done_obj_price = action.done_obj_price;
                }else{
                    let temp = [action.done_obj_price];
                    order.done_obj_price = _.concat(order.done_obj_price, temp);
                }

            }else {
                order.done_obj_price = [];
            }
            // console.log("####", order.done_obj_price);

            return order;
        default:
            return state;
    }
}
